<?php


class menu_module extends CI_Module {
	public function init() {
		$this->load->model('mmenu');
	}
	
	public function active() {
		
	}
	
	public function deactive() {
		
	}
	
	public function admin($config) {
		$this->load->helper('file');
		$config['config']['menu_src'] =  $this->key_value($this->mmenu->get_parent(), 'men_name', 'men_id');
		$view_dir = implode('/', array(BASEPATH, '..', APPPATH, 'views', 'modules',__class__,  'view/'));
		$files = get_filenames($view_dir);
		$config['config']['files']  = array();
		if ($files) foreach ($files as $file) {
			$file = str_replace('.php', '', $file);
			$config['config']['files'][$file] = $file;
		}
		echo $this->view('admin', $config);
	}
	
	public function run($config) {
		if (isset($config['menu_id']) && $config['menu_id']) {
			$config['menu'] = $this->scache->script(implode('.', array('module',__class__,__function__,$config['menu_id']))	,'$this->mmenu->get_menu('.$config['menu_id'].');');
		} else return;
		$view = (isset($config['view'])) ? $config['view']: 'index';
		$this->view('view/'.$view, $config);
	}
	
}
